using System;
using System.Collections.Generic;
using System.Text;
using QLNhaSach.BUS.DTO;
using System.Data;

namespace QLNhaSach.DAO
{
    public class ChiTietHoaDonDAO
    {
        //Hien thi danh sach chi tiet hoa don
        public static DataTable CTHD()
        {
            string sql = "SELECT *FROM CTHoaDon";
            return  Config.AccessHelper.ExecuteQuery(sql);

        }

        //Them mot chi tiet hoa don
        public static bool ThemCTHD(ChiTietHoaDonDTO p)
        {
            try
            {
                string sql = "INSERT INTO CTHoaDon (MaHD, MaSach, DonGia, SoLuong) ";
                sql += " VALUES (" + p.MaHD + ", " + p.MaSach + ", " + p.DonGia + ", " + p.SoLuong + ")";
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        //Cap nhat mot chi tiet hoa don
        public static bool CapNhatCTHD(ChiTietHoaDonDTO p)
        {
            try
            {
                string sql = "UPDATE CTHoaDon SET MaHD='" + p.MaHD + "','" + p.MaSach + "','" +
                            p.DonGia + "','" + p.SoLuong + "'where="+p.MaHD;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        //Xoa mot chi tiet hoa don
        public static bool XoaCTHD(ChiTietHoaDonDTO p)
        {
            try
            {
                string sql = "DELETE  FROM CTHoaDon where=" + p.MaHD;
                Config.AccessHelper.ExecuteNonQuery(sql);
                return true;
            }
            catch
            {
                return false;
            }
        }

        //Load tat ca chi tiet hoa don trong mot hoa don
        public static DataTable LayTatCaCTHD(HoaDonDTO hd)
        {
            string sql = "SELECT *FROM HoaDon where MaHD=" + hd.MaHD;
            return Config.AccessHelper.ExecuteQuery(sql);
        }

    }
}
